import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'dart:math';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';

class DateTimePicker extends StatefulWidget {
  final String title;

  DateTimePicker({Key key, this.title}) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return DateTimePickerState();
  }
}

class DateTimePickerState extends State<DateTimePicker> {
  var textVal = '';

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Column(
        children: <Widget>[
          FlatButton(
              onPressed: () {
                _showDateAndTime(context);
              },
              child: Text('时间日期')),
          Text(textVal),
        ],
      ),
    );
  }

  void _showDateAndTime(BuildContext context) {
    DatePicker.showDateTimePicker(context, showTitleActions: true,
        onChanged: (date) {
      print('变更：${date}');
    }, onConfirm: (date) {
      print('选择：${date}');
      setState(() {
        textVal = date.toString();
      });
    }, currentTime: DateTime.now(), locale: LocaleType.zh);
  }
}
